package Exams.FeiBu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class q5 {
    /*
    会员题1229 安排会议日程
     */
    public List<Integer> minAvailableDuration(int[][] slots1, int[][] slots2, int duration) {
        List<Integer> res = new ArrayList<>();
        Arrays.sort(slots1, Comparator.comparingInt(o -> o[0]));
        Arrays.sort(slots2, Comparator.comparingInt(o -> o[0]));
        int left = 0;
        int right = 0;
        while (left < slots1.length && right < slots2.length) {
            int l, r;
            l = Math.max(slots1[left][0], slots2[right][0]);
            r = Math.min(slots1[left][1], slots2[right][1]);
            if (r - l >= duration) {
                res.add(l);
                res.add(l + duration);
                return res;
            }
            if (slots1[left][1] < slots2[right][1]) {
                left++;
            } else {
                right++;
            }
        }
        return res;
    }
}

